package com.ln.第一遍1105.demo03;

import java.util.Arrays;
import java.util.Optional;

/**
 * @author Ln
 * @version 终极版
 * @date 2022/11/5 15:57
 */
public class Test03 {
    public static void main(String[] args) {
        //reduce规约操作
        //求和
        Integer arr[]={1,2,3,4,5,6};
//        Optional<Integer> reduce = Arrays.stream(arr).reduce((t1, t2) -> t1 += t2);
//        System.out.println(reduce.get());
        Integer reduce2 = Arrays.stream(arr).reduce(0, Integer::sum);
        System.out.println(reduce2);

        //最大值
//        Integer reduce = Arrays.stream(arr).reduce(0, (t1, t2) -> t1 > t2 ? t1 : t2);
        Integer reduce = Arrays.stream(arr).reduce(0, Integer::max);
        System.out.println(reduce);
        //最小值
        Integer reduce1 = Arrays.stream(arr).reduce(0, Integer::min);
        System.out.println(reduce1);
    }
}
